#include "addmask.h"
#include "files.h"
#include "qmessagebox.h"

AddMask::AddMask(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
}

AddMask::~AddMask()
{

}

void AddMask::on_listWidget_doubleClicked()
{
	on_ButtonOk_clicked();
}


void AddMask::on_ButtonOk_clicked()
{
    QString s = ui.EditMask->text();
    int FLAG = 0;

    for(int i = 0; i < s.count(); i++)
    {
        if(s[i] == '.')
            FLAG++;
    }

    if(FLAG == 0 || FLAG > 1)
    {
        QMessageBox::information(this, tr("Внимание"), tr("Маска ввода должна быть в формате *.*"));
    }
    else
    {
        Files *temp = new Files();
        temp->add_item(ui.EditMask->text());
        AddMask::close();
    }
}

void AddMask::on_listWidget_clicked()
{
    ui.EditMask->setText(ui.listWidget->currentItem()->text());
}
